/*
 * @lc app=leetcode.cn id=141 lang=java
 *
 * [141] 环形链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public boolean hasCycle(ListNode head) {
        if(null==head || null == head.next) return false;

        ListNode p = head;
        ListNode q = head;

        while( true ){
            p=p.next;
            q=q.next.next;
            if(p==q){
                return true;
            }else if(null==q || null==q.next){
                return false;
            }
        }

    }
}
// @lc code=end

